package game.dic;

import com.sghd.common.utils.json.JsonUtils;
import game.model.Button;
import game.model.ReturnInfo;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import network.NetServer;
import network.SocketEnum;

import java.util.ArrayList;


@SuppressWarnings("serial")
public class TishiManager {
	
	//消息展示模式
	/** 标准弹窗 **/
	public static String WINDOW_T = "T";
	/** 浮动窗（浮动几秒后自动消失）**/
	public static String WINDOW_F = "F";
	/** 飘窗（从边缘进入，中间停留，然后再出去）**/
	public static String WINDOW_P = "P";
	/** 关闭 */
	public static final int tishiButton_close = -1;
	/** 确定 */
	public static final int tishiButton_ok = 0;
	/** 取消 */
	public static final int tishiButton_canel = 1;
	/** 退出应用 */
	public static final int tishiButton_quiteGame = 2;
	/** 返回大厅 */
	public static final int tishiButton_returnHall = 10;

	public final static String Tishi_T_ConnIll = getTishiT("非法连接，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_SecondLogin = getTishiT("您的账号在其它地方登录了,您被挤出游戏,请检查是否是本人行为", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_MoneyTooLow = getTishiT("金币不足该房间最低要求", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_MoneyTooHigh = getTishiT("金币已超出该房间限制", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_No_Seat = getTishiT("该场已无空位置啦,换个场玩玩", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_JoinDesk_Fail = getTishiT("进入桌子失败，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_JoinRoom_Fail = getTishiT("进入房间失败，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_Operate_Fail = getTishiT("操作失败，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_JieSuan_Fail = getTishiT("金币异常，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_HavePlayer = getTishiT("该桌已经被别人抢先一步啦，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public final static String Tishi_T_FaPai_Ill = getTishiT("发牌时出错，不会扣除当轮投注，请重新进入游戏。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});

	public static final String Tishi_T_LongNoOperate = getTishiT("长时间未操作，被系统踢出房间。", WINDOW_T, new ArrayList<Button>() {
		{
			add(new Button(tishiButton_returnHall, null));
		}
	});
	public final static String Tishi_F_ChangeBet_Fail = getTishiT("选择投注失败", WINDOW_F, null);
	public final static String Tishi_F_Money_NotEnough = getTishiT("金币不足当前档位，系统已为您自动降档，请重新点击开始。", WINDOW_F, null);
	public final static String Tishi_Close_Success = getTishiT("关闭成功", WINDOW_F, null);
	public final static String Tishi_Close_Fail = getTishiT("关闭失败", WINDOW_F, null);
	public final static String Tishi_Start_Success = getTishiT("重启成功", WINDOW_F, null);
	public final static String Tishi_Start_Fail = getTishiT("重启失败", WINDOW_F, null);
	public final static String Tishi_Read_Success = getTishiT("读取成功", WINDOW_F, null);
	public final static String Tishi_Read_Fail = getTishiT("读取失败", WINDOW_F, null);
	public final static String Tishi_Modity_Success = getTishiT("修改成功", WINDOW_F, null);
	public final static String Tishi_Modity_Fail = getTishiT("修改失败", WINDOW_F, null);
	public final static String Tishi_Send_Success = getTishiT("发送成功", WINDOW_F, null);
	public final static String Tishi_Send_Fail = getTishiT("发送失败", WINDOW_F, null);
	public static String getTishiT(String value, String type, ArrayList<Button> buttons) {
		ReturnInfo rInfo = new ReturnInfo();
		rInfo.setType(type);
		rInfo.setInfo(value);
		if (buttons != null) {
			for (int i = 0; i < buttons.size(); i++) {
				Button button = buttons.get(i);
				rInfo.addButton(button);
			}
		}
		return JsonUtils.object2String(rInfo);
	}

	public static void sendTishi(Channel channel, String message){
		String tishi = getTishiT(message, WINDOW_T, new ArrayList<Button>(){
			{
				add(new Button(tishiButton_returnHall, null));
			}
		});
		Unpooled.copiedBuffer((SocketEnum.infoI + NetServer.MSG_SPLIT + tishi + NetServer.MSG_END).getBytes());
	}

}
